package cn.mafangui.hotel.service.impl;

import cn.mafangui.hotel.req.AddStallReq;
import cn.mafangui.hotel.entity.GarageStall;
import cn.mafangui.hotel.mapper.GarageStallMapper;
import cn.mafangui.hotel.req.PageQueryReq;
import cn.mafangui.hotel.service.GarageStallService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: kalpa
 * @date: 2022/3/18
 * @version: 1.0
 * Description: No Description
 */
@Service
public class GarageStallServiceImpl implements GarageStallService {
    @Resource
    GarageStallMapper garageStallMapper;


    @Override
    public int add(AddStallReq addStallReq) {
        GarageStall garageStall = new GarageStall();
        BeanUtils.copyProperties(addStallReq, garageStall);
        // 如果为空设置默认值
        if(ObjectUtils.isEmpty(garageStall.getStatus())){
            garageStall.setStatus(0);
        }
        return garageStallMapper.add(garageStall);
    }

    @Override
    public int update(GarageStall garageStall) {
        return garageStallMapper.update(garageStall);
    }

    @Override
    public List<GarageStall> getAllByPage(PageQueryReq req) {
        PageHelper.startPage(req.getPage(), req.getSize());
        return garageStallMapper.getAll();
    }

    @Override
    public int delete(Integer id) {
        return garageStallMapper.delete(id);
    }


}
